home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 August: Tool Chest / Dev.CD Aug 00 TC Disk 2.toast / pc / sample code / quicktime / quicktime for java / imagecompositing / src / profilecompositor.java < prev    next >
Encoding:
Java Source  |  2000-06-23  |  2.4 KB  |  77 lines

  1. /*
  2.  * QuickTime for Java SDK Sample Code
  3.  
  4.    Usage subject to restrictions in SDK License Agreement
  5.  * Copyright: © 1996-1999 Apple Computer, Inc.
  6.  
  7.  */
  8. import quicktime.app.anim.*;
  9. import quicktime.qd.*;
  10. import quicktime.*;
  11. import java.util.*;
  12. // We use this class to profile just the tickling times (incl. blit) of the compositor
  13.  
  14. // we could expand this profiling to include the time between each tickle call, the number of tickle calls a second, etc.
  15. public class ProfileCompositor extends Compositor {
  16.     public ProfileCompositor (QDGraphics gw, QDColor bgColor, int scale, int period) throws QTException {
  17.         super (gw, bgColor, scale, period);
  18.     }
  19.     
  20.     
  21.     int profileCount = 0;
  22.     long startTime, stopTime;
  23.     boolean isProfiling;
  24.     Vector tickleTimes = new Vector();
  25.     long previousTime;
  26.     
  27.         //the tickle method will invoke the idle method to blit
  28.         // as such we can get an idea of the blit time as well
  29.         //by overiding the idle method and profiling it when we
  30.         // are profiling the tickle method
  31.     public boolean tickle (float er, int time) throws QTException {
  32.         //profile the tickle method and print it every 40 times
  33.         isProfiling = profileCount++ % 40 == 0;
  34.         startTime = System.currentTimeMillis();    
  35.         
  36.         boolean ret = super.tickle (er, time);
  37.         
  38.         if (isProfiling) {
  39.             stopTime = System.currentTimeMillis();
  40.             System.out.println (",tickle:" + (stopTime - startTime) + " msecs");
  41.             if (tickleTimes.size() != 0) {
  42.                 Enumeration iter = tickleTimes.elements();
  43.                 Integer min = new Integer (1000);
  44.                 Integer max = new Integer (0);
  45.                 int total = 0;
  46.                 
  47.                 while (iter.hasMoreElements()) {
  48.                     Integer el = (Integer)iter.nextElement();
  49.                     if (el.intValue() > max.intValue())
  50.                         max = el;
  51.                     if (el.intValue() < min.intValue())
  52.                         min = el;
  53.                     total += el.intValue();
  54.                 }
  55.                 System.out.println ("min=" + min.intValue() + ",max=" + max.intValue() + ",AVG=" + (total / tickleTimes.size()) + "," + tickleTimes);
  56.             }
  57.             tickleTimes = new Vector();
  58.         }
  59.         tickleTimes.addElement (new Integer ((int)(startTime - previousTime)));
  60.         previousTime = startTime;
  61.         return ret;
  62.     }
  63.     
  64.     long idleStartTime, idleStopTime;
  65.     
  66.     protected void idle () throws QTException {
  67.         if (isProfiling)
  68.             idleStartTime = System.currentTimeMillis();
  69.         
  70.         super.idle();
  71.         
  72.         if (isProfiling) {
  73.             idleStopTime = System.currentTimeMillis();
  74.             System.out.print ("* * * SpriteWorldIdle:" + (idleStopTime - idleStartTime) + " msecs");
  75.         }
  76.     }
  77. }